package com.inspur.icity.bus.base.core.model;

import java.util.HashMap;
import java.util.Map;

/**
 * 统一返回数据结果
 * Created by Administrator on 2017/10/22 0022.
 */
public class BaseResult {


    public static final int SUCCESS_CODE = 1;
    public static final int FAIL_CODE = 0;

    public static final String SUCCESS_MESSAGE = "SUCCESS";
    public static final String FAIL_MESSAGE = "ERROR";


    // 状态码：1成功，其他为失败
    public int code;

    // 成功为success，其他为失败原因
    public String message;

    // 数据结果集
    public Object data;

    public BaseResult(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 返回正确状态结果集
     * @return
     */
    public static BaseResult success(Object data){
        return new BaseResult(SUCCESS_CODE,SUCCESS_MESSAGE,data);
    }

    /**
     * 返回错误状态结果集
     * @param data
     * @return
     */
    public static BaseResult fail(Object data){
        return new BaseResult(FAIL_CODE,FAIL_MESSAGE,data);
    }

    /**
     * 返回错误状态结果集
     * @param errorCode
     * @param errorMessage
     * @return
     */
    public static BaseResult fail(Integer errorCode,String errorMessage){
        Map<String,Object> map = new HashMap<>();
        map.put("errorCode",errorCode);
        map.put("errorMessage",errorMessage);
        return new BaseResult(FAIL_CODE,FAIL_MESSAGE,map);
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
